#!/usr/bin/env python

from xml.dom import minidom as dom

if __name__=='__main__':
  f = file('factory.svg')
  #print f.read().split('\n')
  xmlstr = f.read()
  newstr = xmlstr.replace('#a2554f', '#3977d3')
  f.close()
  
  g = file('test2.svg', 'w')
  g.write(newstr)
  g.close()
  
  '''
  doc =  dom.parseString(''.join(f.xreadlines()))
  
  svg = doc.getElementsByTagName('svg')
  svg_el = svg[0]
  def_el = svg_el.getElementsByTagName('defs')[0]
  gradients = def_el.getElementsByTagName('linearGradient')
  for g in gradients:
    stops = g.getElementsByTagName('stop')
    if len(stops) != 0:
      print g.getAttribute('id')
      for stop in stops:
        if stop.getAttribute('offset') == '0':
          print stop.getAttribute('style')
          stop.setAttribute('style', 'stop-color:#e00000;stop-opacity:1;')
  
  doc.writexml(file('test2.svg', 'w'))
  
  doc.unlink()
  '''
  
